<?php
/**
 * Plugin registration script.
 * This script does plugin registration, it actually calls {@link Psa_Plugin::register()} 
 * and {@link Psa_Plugin::save()} methods.
 * See their documentation for details about the plugin registration process.
 * When you add some new plugins (new classes that extends <i>Psa_Plugin_</i> classes, 
 * not methods inside already registered classes) you must register plugins to save data
 * like path and type into the database. After that you can call plugin methods with
 * {@link psa_run_plugins()} function.
 * 
 * This script should be called directly in web browser by typing url like: 
 * <kbd>http://my_site.com/psa/register_plugins.php</kbd>. You don't have to use this
 * script for plugin registration. It is here for your convenience, but you can do it in some 
 * of your model plugins if you like, by calling these two methods:
 * <code>
 * // register plugins
 * $plugins_data = Psa_Plugin::get_instance()->register();
 * 
 * // save registered data
 * Psa_Plugin::get_instance()->save($plugins_data);
 * </code>
 * 
 * If {@tutorial psa_features.pkg#developmode develop mode} is on, registration is done on every 
 * request so you don't need to call this script. This script can be useful on production 
 * site when you add some new plugin class.
 * 
 * <b>Note:</b> Do not allow everyone to call this script.
 *
 * @link http://code.google.com/p/phpstartapp/
 * @author Bojan Mauser <bmauser@gmail.com>
 * @copyright Bojan Mauser 2009
 * @package psa
 * @see Psa_Plugin::register()
 * @see Psa_Plugin::save()
 * @see psa_run_plugins()
 * @version $Id: register_plugins.php 464 2009-03-24 00:30:12Z bmauser $
 * @todo Put some security into this script or remove it from psa folder.
 */

/**
 *
 */


// PSA main dir
$PSA_CFG['folders']['basedir'] = dirname(__FILE__);


// include required files
include_once 'config.php';
include_once 'scripts/Psa_Pdo.class.php';
include_once 'scripts/Psa_Singleton.class.php';
include_once 'scripts/Psa_Logger.class.php';
include_once 'scripts/Psa_Plugin.class.php';
include_once 'scripts/functions.php';


// database object
$psa_database = new Psa_Pdo();

// register plugins
$plugins_data = Psa_Plugin::get_instance()->register();

// echo results
echo "Plugins data:";
prs($plugins_data);

// save to database
if(Psa_Plugin::get_instance()->save($plugins_data))
	echo "Plugins data saved to database (registered). OK.";
else
	echo "Error. Data not saved to database.";

